/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Zombies;

import Controller.Table;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JPanel;


/**Autores:
 * Hugo Hiroshi Yamamura
 * Marina Coimbra Viviani
 *
 * Class Zombie
 * Classe Pai de todos os outros zumbis
 */
public class Zombie {
    

    private String zombie = "/Sprites/haunter.gif";

    private int x;
    private int y;
    private int width;
    private int height;
    private boolean visible;
    private Image image;
    
    private int imagex;
    private int imagew;
    
    private int type;

    public int getType() {
        return type;
    }
  /**
 * Construtor: Zombie
 * Constroi novo zumbi.
 */

    public Zombie() {
        
        Random rand = new Random();
        Table table = new Table();
        ImageIcon ii = new ImageIcon(this.getClass().getResource(zombie));
        image = ii.getImage();
        width = 37;
        height = image.getHeight(null);
        visible = true;

        this.x = 800;
        this.y = table.insertY(rand.nextInt(table.getYEND() - table.getYBEGIN() - table.getYTAM()) + table.getYBEGIN());
        
        if( this.y == -1){
            this.y = table.insertY(table.getYBEGIN() + 1);
          }
       
    }
    
     /*
    *
    * Metodo: paint
    * Funcionamento: pinta o zumbi no JPanel.
    */
    public void paint(Graphics g, JPanel panel){
        if(this.isVisible()){
            Graphics2D g2d = (Graphics2D)g;
            g2d.drawImage(this.getImage(), this.getX(), this.getY(), this.getX()+ this.getImagew(), this.getY() + this.getHeight(), this.getImagex(), 0, this.getImagex()+ this.getImagew(), this.getHeight(), panel);
        }
    }

     /*
     * Método move
     * @param times : eh um desacelerador da função baseado em quantas vezes foi rodado o cronometro
     * Funcionamento: Anima a imagem, impede o zumbi de andar para fora da tabela e faz o zumbi andar
     */
    public void move(int times) {
        if(times % 20 == 0)
        if(imagex != 2 *imagew)
                imagex += imagew;
            else imagex = 0;
        
        if (x < 0) 
            x = 800;
        x -= 1;
    }


    /*
    *
    * Metodo: dealCollision
    * Funcionamento: lida com a colisão do Haunter com pokebola, personagem principal e a casa; se colidiu, desaparece da tela
    */
    public void dealCollision(){
        this.setVisible(false);
    }

    /*
     * Metodo: setVisible
     * Funcionamento: apaga ou mostra o objeto na tela
     */
    public void setVisible(Boolean visible) {
        this.visible = visible;
    }

    /*
    * --------------------------
    *  Getters e Setters
    * -------------------------
    */
    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public boolean isVisible() {
        return visible;
    }


    public Image getImage() {
        return image;
    }

    public Rectangle getBounds() {
        return new Rectangle(x, y, imagew, height);
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getImagew() {
        return imagew;
    }

    public void setImagew(int imagew) {
        this.imagew = imagew;
    }

    public int getImagex() {
        return imagex;
    }

    public void setImagex(int imagex) {
        this.imagex = imagex;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public void setImage(Image image) {
        this.image = image;
    }
    
    
    
}
    
